/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */

package org.ipig.commons.conf.mongo;

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Mongo Conf
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: MongoConf.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $$
 * @since 1.0
 */
@Data
@ToString
public class MongoConf implements Serializable {
    /**
     * 连接字段串,多个地址以逗号隔开
     */
    private String address;
    /**
     * DB名称
     */
    private String dbName;
    /**
     * 用户名
     */
    private String userName = "";
    /**
     * 密码
     */
    private String password = "";
    /**
     * 与目标数据库能够建立的最大connection数量
     */
    private int capacity = 50;
    /**
     * 如果当前所有的connection都在使用中，则每个connection上可以有多少个线程排队等待
     */
    private int threadsAllowedToBlockForConnectionMultiplier = 30;
    /**
     * 控制安全写入级别 0最高吞吐量写入,不安全, 1:一副本写入默认, 2:二副本写入, 3:三副本写入
     */
    private int optionsWriteConcern = 1;
    /**
     * 控制安全读取级别  ：primary:从主节点读取。primaryPreferred:优先从主节点读取。secondary:从从节点读取。secondaryPreferred:优先从从节点读取。nearest:根据网络距离就近读取
     */
    private String optionsReadPreference = "primary";

    /**
     * 一个线程访问数据库的时候，在成功获取到一个可用数据库连接之前的最长等待时间的时间
     * 这里比较危险，如果超过maxWaitTime都没有获取到这个连接的话，该线程就会抛出Exception
     * 故这里设置的maxWaitTime应该足够大，以免由于排队线程过多造成的数据库访问失败
     */
    private int maxWaitTime = 1000 * 60 * 2;
    /**
     * 与数据库建立连接的连接超时时间
     */
    private int connectTimeout = 1000 * 60 * 1;
    private int maxConnectionIdleTime = 1000 * 60;
    private int maxConnectionLifeTime = 0;
    private int socketTimeout = 0;
    private int serverSelectionTimeout = 0;

    //com.mongodb.updaterConnectTimeoutMS
    private int heartbeatConnectTimeout = 20000;
    //com.mongodb.updaterSocketTimeoutMS
    private int heartbeatSocketTimeout = 20000;
    //com.mongodb.updaterIntervalMS
    private int heartbeatFrequency = 10000;
    //com.mongodb.updaterIntervalNoMasterMS
    private int minHeartbeatFrequency = 500;
    //com.mongodb.slaveAcceptableLatencyMS
    private int localThreshold = 15;
    // 其它属性
    private Map<String, Object> props = new HashMap<>();
}
